home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15065 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: HOPPER.ACM.ORG!news
  2. From: varnk@e62.diebold.com (Ken Varn)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: strstream destruction
  5. Date: 3 Apr 1996 13:11:16 GMT
  6. Organization: Diebold
  7. Message-ID: <4jttdk$i6v@HOPPER.ACM.ORG>
  8. References: <315AD92C.726D@itd.ssb.com> <4jhgt0$17f@piper.logicon.com> <4joujt$72p@lib104.its.rpi.edu>
  9. NNTP-Posting-Host: 199.218.232.47
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <4joujt$72p@lib104.its.rpi.edu>, floydb1@lib104.its.rpi.edu 
  15. says...
  16. />
  17. />
  18. />This works for me:
  19. />
  20. />String StrStrFunc ( void )      // some function using strstream
  21. />{
  22. />        ostrstream a_stream ;   // 
  23. />        String  a_string ;      // a 'string' class (char *)
  24. />
  25. />        a_stream << a_variable  // any type
  26. />                 << ends ;      // null terminate string
  27. />
  28. />        a_string = a_stream.str() ; // get the buffer
  29. />
  30. />        a_stream.freeze(0) ;    // unfreeze buffer
  31. />
  32. />        return ( a_string ) ;   // out of scope, deletes string
  33. />                                // returns copy
  34. />}
  35.  
  36. Just curious about this as it indirecly applies to something that I am 
  37. wondering about.  If a_stream is declared globally or as a data member of a 
  38. class, and you were to perform this function with it, would its internal 
  39. buffer get dynamically reallocated on each call, or would the object maintain 
  40. its own internal buffer and increase or decrease its size as needed (see 
  41. below)? 
  42.  
  43. ostrstream a_stream;
  44.  
  45. String StrStrFunc ( void )      // some function using strstream
  46. {
  47.         String  a_string ;      // a 'string' class (char *)
  48.  
  49.         a_stream << a_variable  // any type
  50.                  << ends ;      // null terminate string
  51.  
  52.         a_string = a_stream.str() ; // get the buffer
  53.  
  54.         a_stream.freeze(0) ;    // unfreeze buffer
  55.  
  56.         return ( a_string ) ;   // out of scope, deletes string
  57.                                 // returns copy
  58. }
  59.  
  60.